/**
 * @file categories/dp/linear/cf474d/main.cpp
 * @brief
 * @see
 * @author Ruiming Guo (guoruiming@stu.scu.edu.cn)
 * @copyright 2022
 * @date 2022/7/6 14:35:48
 **/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const int N = 1e5 + 10;
ll dp[N], sum[N];
const int mod = 1e9 + 7;
int main() {
  // High rating and good luck!
  int t, k;
  cin >> t >> k;
  for (int i = 0; i < N; ++i) {
    if (i < k)
      dp[i] = 1;
    else
      dp[i] = (dp[i - 1] + dp[i - k]) % mod;
  }
  sum[0] = dp[0];
  for (int i = 1; i < N; ++i) {
    sum[i] = (sum[i - 1] + dp[i]) % mod;
  }
  while (t--) {
    int a, b;
    cin >> a >> b;
    cout << (sum[b] - sum[a - 1] + mod) % mod << '\n';
  }
  return 0;
}
